package cn.wolfcode.luowowo.website.web.controller;

import cn.wolfcode.luowowo.article.domain.Getgogo;
import cn.wolfcode.luowowo.article.service.IGetgogoService;
import cn.wolfcode.luowowo.article.service.ISubjectSerivce;
import cn.wolfcode.luowowo.article.service.ITicketService;
import cn.wolfcode.luowowo.article.service.IVipticketService;
import cn.wolfcode.luowowo.common.utils.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping
public class TicketController {

    @Reference
    private ITicketService ticketService;

    @Reference
    private ISubjectSerivce subjectSerivce;

    @Reference
    private IVipticketService vipticketService;

    @Reference
    private IGetgogoService getgogoSerivce;

    @RequestMapping("ticket")
    public String list(Model model){
        model.addAttribute("tickets",ticketService.selectAll());
        return "ticket/index";
    }

    @RequestMapping("homePage/reloadSubAndProd")
    private String reloadSubAndProd(Model model,Long ajaxDestId){
        model.addAttribute("subject",subjectSerivce.listId(ajaxDestId));
        model.addAttribute("stst",ticketService.getLists(ajaxDestId));
        return "ticket/sundand";
    }

    @RequestMapping("homePage/reloadProd")
    private String reloadProd(Model model,Long ajaxDestId, Long ajaxSubjectId){
        model.addAttribute("subject",ticketService.getId(ajaxDestId,ajaxSubjectId));
        return "ticket/ticket";
    }

    @RequestMapping("ticket/detail")
    private String detail(Model model,Long tid){
        model.addAttribute("ticket",ticketService.selectByPrimaryKey(tid));
        model.addAttribute("ticketDetail",vipticketService.selectByPrimaryKey(tid));
        return "ticket/detail";
    }

    @RequestMapping("ticket/addOrder")
    private String addOrder(Model model,Long tid){
        model.addAttribute("ticket",ticketService.selectByPrimaryKey(tid));
        model.addAttribute("ticketDetail",vipticketService.selectByPrimaryKey(tid));
        return "ticket/addOrder";
    }

    @RequestMapping("/gogo")
    @ResponseBody
    private Object gogo(Model model, Getgogo getgogo){
        System.out.println(getgogo);
        getgogoSerivce.insert(getgogo);
        return AjaxResult.SUCCESS;
    }
}
